<template>
  <div>
    <Headline
      :headline1="$t('m.FaceRecognition') + '  /  '"
      :headline2="$t('m.FaceAuthorization')"
    />
    <a-card style="width: 100%;display:flex">
      <a-tabs
        default-active-key="1"
        @change="callback"
        style="
          margin-bottom: 60px;
          border-bottom: 1px solid #e8e8e8;
          padding-bottom: 20px;
          width:28%;
        "
      >
        <a-tab-pane key="1" :tab="$t('m.Equipment')" force-render>
          <a-input-search
            v-model="forminitial.key"
            style="width: 200px; margin-bottom: 20px; margin-right: 15px"
            :placeholder="$t('m.PleaseEnterYourSearchTerms')"
            enter-button
            @search="onSearchB"
          />
          <a-table
            style="width: 300px"
            size="small"
            :columns="columns"
            :rowKey="(record) => record.id"
            :data-source="data"
            :pagination="false"
            :row-selection="{
              onChange: onSelectChange,
              selectedRowKeys: selectedRowKeysList,
            }"
            bordered
          />
          <a-pagination
        style="margin-top: 15px"
        show-size-changer
        :default-current="1"
        :total="totalC"
        @change="PagesC"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="onShowSizeChangeC"

      />
        </a-tab-pane>
        <a-tab-pane key="2" :tab="$t('m.Organization')">
          <select-tree
            :placeholder="$t('m.pleaseChoose')"
            @checkData="argumentSelect"
          />

          <a-select default-value="0" style="width: 120px;margin-left:15px;"
           @change="selectChangetree">
      <a-select-option value="0">
        职工
      </a-select-option>
      <a-select-option value="1">
        学生
      </a-select-option>

    </a-select>
        </a-tab-pane>
      </a-tabs>
      <div class="rig">
        <a-select
        style="width: 100px; margin-right: 15px"
        default-value="-1"
        @change="treeChange"
      >
        <a-select-option
          :value="item.code"
          :key="item.code"
          v-for="item in treeDataList"
        >
          {{ item.name }}
        </a-select-option>
      </a-select>

      <a-select style="width: 80px" default-value="0" @change="treeChangeB">
        <a-select-option
          :value="item.code"
          v-for="item in dataTreeList"
          :key="item.code"
        >
          {{ item.name }}
        </a-select-option>
      </a-select>
      <a-input-search
        v-model="forminitialB.key"
        style="width: 200px; margin-left: 15px; margin-right: 15px"
        :placeholder="$t('m.PleaseEnterYourSearchTerms')"
        enter-button
        @search="onSearch"
      />
      <a-checkbox @change="onChange">
        {{ $t("m.WhetherToDisplayChildNodes") }}
      </a-checkbox>
      <a-button
        type="primary"
        v-if="isTrue('face:auth:redown')"
        @click="reDownload"
        style="margin-right: 15px"
        >{{ $t("m.ReDownload") }}</a-button
      >
      <a-button
        type="primary"
        style="margin-right: 15px"
        v-if="isTrue('face:auth:add')"
        @click="addshouquan"
        >{{ $t("m.TheNewAuthorization") }}</a-button
      >
      <a-button
        type="danger"
        @click="deleteAll"
        v-if="isTrue('face:auth:del')"
        >{{ $t("m.DeleteInBatches") }}</a-button
      >
      <a-table
      :scroll="{ x: 1300}"
        style="margin-top: 20px;"
        :columns="columnsA"
        :rowKey="(record) => record.id"
        :data-source="dataA"
        :pagination="false"
        bordered
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChangeA,
        }"
      >
        <div slot="tags" slot-scope="text, tags, i">
          <a
            size="small"
            style="margin-right: 5px"
            @click="show(text, tags, i)"
            >{{ $t("m.Examine") }}</a
          >
          <a
            size="small"
            style="margin-right: 5px"
            v-if="isTrue('face:auth:update')"
            @click="edit(text, tags, i)"
            >{{ $t("m.Modification") }}</a
          >
        </div>
      </a-table>
      <a-pagination
        style="margin-top: 15px"
        show-size-changer
        :default-current="1"
        :total="total"
        @change="Pages"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="onShowSizeChange"
        class="pages"
      />
      </div>

    </a-card>
    <a-modal
      @cancel="handleCancel"
      :title="$t('m.picture')"
      :visible="visible"
      :footer="null"
      style="text-align: center"
    >
      <img style="width:300px;height:300px;" :src="imgSrc" />
    </a-modal>
    <a-modal
      @cancel="handleCancelA"
      :title="$t('m.SelectPersonnel')"
      :visible="visibleA"
      @ok="okA"
      width="900px"
      :cancelText="$t('m.Cancel')"
              :okText="$t('m.Ok')"
              :footer="null"
    >
      <a-steps :current="current">
        <a-step v-for="item in steps" :key="item.title" :title="item.title" />
      </a-steps>
      <div class="steps-content" v-if="current == 0 ? true : false">
        <select-tree
          :placeholder="$t('m.pleaseChoose')"
          @checkData="argumentSelectA"
        />
        <a-select
          style="width: 80px; margin-left: 20px"
          default-value="-1"
          @change="treeChangeA"
        >
          <a-select-option
            :value="item.code"
            :key="item.code"
            v-for="item in treeListD"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>
        <a-input-search
          style="width: 200px; margin-left: 20px; margin-right: 20px"
          :placeholder="$t('m.PleaseEnterYourSearchTerms')"
          enter-button
          v-model="forminitialH.key"
          @search="onSearchA"
        />
        <a-checkbox @change="onChangeA">
          {{ $t("m.WhetherToDisplayChildNodes") }}
        </a-checkbox>
        <a-transfer
          style="margin-top: 20px"
          :locale="{ itemUnit: '项', itemsUnit: '项' }"
          :data-source="mockData"
          :target-keys="targetKeys"
          :show-search="showSearch"
          :filter-option="
            (inputValue, item) => item.title.indexOf(inputValue) !== -1
          "
          :show-select-all="false"
          @change="onChangeB"
        >
          <template
            slot="children"
            slot-scope="{
              props: { direction, filteredItems, selectedKeys },
              on: { itemSelectAll, itemSelect },
            }"
          >
            <a-table
             :pagination="direction === 'left'?ipagination:Rightipagination"
              :row-selection="
                getRowSelection({
                  selectedKeys,
                  itemSelectAll,
                  itemSelect,
                })
              "
              :columns="direction === 'left' ? leftColumns : rightColumns"
              :data-source="filteredItems"
              bordered
            />
          </template>
        </a-transfer>
      </div>
      <div class="steps-content" v-else>
        <a-table
          size="small"
          :columns="columnsB"
          :rowKey="(record) => record.id"
          :data-source="dataB"
          :pagination="false"
          :row-selection="{
            onChange: onSelectChangeB,
            selectedRowKeys: selectedRowKeysListB,
            type: 'radio',
          }"
          bordered
        />
        <a-pagination
          style="margin-top: 10px"
          show-size-changer
          :default-current="1"
          :total="totalA"
          @change="PagesA"
          :pageSizeOptions="['5', '10', '30', '40']"
          @showSizeChange="onShowSizeChangeA"
          class="pages"
        />
      </div>
      <div class="steps-action">
        <a-button
          v-if="current < steps.length - 1"
          type="primary"
          @click="next"
        >
          {{$t('m.Next')}}
        </a-button>
        <a-button
          v-if="current == steps.length - 1"
          type="primary"
          @click="stepOk"
        >
          {{$t('m.Done')}}
        </a-button>
        <a-button v-if="current > 0" style="margin-left: 8px" @click="prev">
          {{$t('m.Previous')}}
        </a-button>
      </div>
    </a-modal>
    <a-modal
      @cancel="handleCancelB"
      :title="$t('m.SelectionPeriodScheme')"
 :cancelText="$t('m.Cancel')"
      :okText="$t('m.Ok')"
      :visible="visibleB"
      @ok="okB"
      width="1200px"
    >
      <a-table
        :columns="columnsB"
        :data-source="dataB"
        :rowKey="(record, i) => record.id"
        bordered
        size="middle"
        :pagination="false"
        :row-selection="{
          onChange: onSelectChangeK,
          selectedRowKeys: selectedRowKeysListK,
        }"
      />
      <a-pagination
        style="margin-top: 10px"
        show-size-changer
        :default-current="1"
        :total="totalB"
        @change="PagesB"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="onShowSizeChangeB"
        class="pages"
      />
    </a-modal>
    <Delete ref="bindownload" :dalete="huadalete" @confirm="bindownload" />
    <Delete ref="delItem" :dalete="huadaleteB" @confirm="bindel" />
  </div>
</template>

<script>
import difference from "lodash/difference";
import Headline from "@/components/Headline";
import Delete from "@/components/Delete";
import {
  getDeviceList,
  getFaceRecord,
  getAuthorizeList,
  redown,
  getWidgetComboboxList,
  getStaffOrStudInfoList,
  saveAuthorize,
  delAuthorize,
  getTimeSchemeList,
  updateTimeScheme,
} from "@/api/faceRecognition";
import { getPerages } from "@/api/keraStase";
import { getStaff } from "@/api/perAges";
import SelectTree from "@/components/common/SelectTree";
import { getWidgetDictionaryList } from "@/api/entrance/cloudDoor";
import { Setperms } from "@/assets/js/setperms";

export default {
  name: "Faceauthorization",
  components: { Headline, SelectTree, Delete },
  data() {
    return {
      totalC:0,
      selectedRowKeysListK: [],
      totalB: 0,
      visibleB: false,
      forminitialJ: {
        start: 0,
        page: 1,
        limit: 10,
      },
      dataB: [],
      forminitialK: {
        page: 1,
        start: 0,
        limit: 10,
        key: "",
      },
      columnsB: [
        {
          title: this.$t("m.Slotnumber"),
          dataIndex: "timeIndex",
        },
        {
          title: this.$t("m.SlotName"),
          dataIndex: "timeName",
        },
        {
          title: this.$t("m.timezone1"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTime",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTime",
            },
          ],
        },
        {
          title: this.$t("m.timezone2"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTimeExt1",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTimeExt1",
            },
          ],
        },
        {
          title: this.$t("m.timezone3"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTimeExt2",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTimeExt12",
            },
          ],
        },
        {
          title: this.$t("m.timezone4"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTimeExt3",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTimeExt13",
            },
          ],
        },
        {
          title: this.$t("m.timezone5"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTimeExt4",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTimeExt4",
            },
          ],
        },
        {
          title: this.$t("m.timezone6"),
          children: [
            {
              title: this.$t("m.Start"),
              dataIndex: "startTimeExt5",
            },
            {
              title: this.$t("m.End"),
              dataIndex: "endTimeExt5",
            },
          ],
        },
      ],
      ipagination:{
        defaultPageSize:5,
        pageSizeOptions:['5','10','20'],
        showSizeChanger:true,
        // showQuickJumper:true,
        onShowSizeChange: this.pageSizeChange,
        onChange: this.pageChange,
        total:0
      },
      Rightipagination:{
         defaultPageSize:5,
      },
      huadalete: {
        titles: this.$t("m.DownloadPrompt"),
        type: "warning",
        text: "确认删除这一条数据吗",
      },
      huadaleteB: {
        titles: this.$t("m.DeleteThePrompt"),
        type: "warning",
        text: this.$t("m.AreYouSureToDeleteThisData"),
      },
      data: [],
      columns: [
        { title: this.$t("m.EquipmentNumber"), dataIndex: "machineid" },
        { title: this.$t("m.Name"), dataIndex: "devname" },
      ],
      forminitialH: {
        start: 0,
        limit:5,
        page: 1,
        infoType: 0,
        status: 1,
        key: "",
        property: "-1",
        ymOrgTreeCode: "",
        vChild: false,
      },
      selectedRowKeysList: [],
      forminitialI: {
        devIds: "",
        timeSchemeId: 1,
        ids: "",
        allowCard: 0,
      },
      forminitialG: {
        table: "tb_face_timescheme",
        insertall: "0|全部",
        where: "1=1",
        fields: "id as code,timename as name",
        orderby: "timeindex asc",
      },
      forminitial: {
        start: 0,
        limit: 10,
        devClass: 9,
        page: 1,
        key: "",
      },
      dataA: [],
      columnsA: [
        { title: this.$t("m.jobnumber"), dataIndex: "stafforstucode" },
        { title: this.$t("m.Name"), dataIndex: "stafforstuname" },
        { title: this.$t("m.Sex"), dataIndex: "sex" },
        { title: this.$t("m.CardNumber"), dataIndex: "cardno" },
        { title: this.$t("m.AffiliatedUnit"), dataIndex: "custorgname" },
        { title: this.$t("m.EquipmentNumber"), dataIndex: "machineid" },
        { title: this.$t("m.EquipmentName"), dataIndex: "devname" },
        { title: this.$t("m.SlotName"), dataIndex: "timename" },
        {
          title: this.$t("m.WhetherCreditCardsAreAllowed"),
          dataIndex: "allowcard",
        },
        {
          title: this.$t("m.DownloadStatus"),
          dataIndex: "downstatus",
          customRender: function (text) {
            if (text == "0") {
              return "待下载";
            }
            if (text == "1") {
              return "已下载";
            }
          },
        },
        //{ title: "下载信息", dataIndex: "devname" },
        { title: this.$t("m.privilegedTime"), dataIndex: "createdate" },
        { title: this.$t("m.privilegedperson"), dataIndex: "nickname" },
        {
          title: this.$t("m.Operation"),
          dataIndex: "tags",
          scopedSlots: { customRender: "tags" },
        },
      ],
      forminitialB: {
        downStatus: -1,
        timeSchemeId: 0,
        viewChild: false,
        devIds: "",
        ymorgTreeCode: "",
        infoType: 0,
        page: 1,
        start: 0,
        limit: 10,
      },
      total: 0,
      visible: false,
      imgSrc: "",
      treeDataList: [],
      forminitialC: {
        groupcode: "SYS0000025",
        insertall: "-1|全部",
        where: "code<> -1 and code <> -100",
      },
      selectedRowKeys: [],
      downIdList: "",
      visibleA: false,
      forminitialD: {
        groupcode: "SYS0000055",
        insertall: "-1|全部",
        where: "attr1=1",
      },
      treeListD: [],
      forminitialE: {
        ymOrgTreeCode: "",
        infoType: 1,
        status: -1,
        vChild: false,
        key: "",
        page: 1,
        start: 0,
        limit: 10,
      },
      dataTreeList: [],
      mockData: [],
      selectedKeys: [],
      targetKeys: [],
      current: 0,
      steps: [
        {
          title: "First",
          content: "First-content",
        },
        {
          title: "Second",
          content: "Second-content",
        },
      ],
      showSearch: false,
      disabled: false,
      leftColumns: [
        {
          dataIndex: "stafforstucode",
          title: this.$t("m.jobnumber"),
        },
        {
          dataIndex: "stafforstuname",
          title: this.$t("m.Name"),
        },
        {
          dataIndex: "sex",
          title: this.$t("m.Sex"),
          customRender: function (text) {
            if (text == "1") {
              return "男";
            }
            if (text == "2") {
              return "女";
            }
          },
        },
        {
          dataIndex: "cardno",
          title: this.$t("m.CardNumber"),
        },
        {
          dataIndex: "orgname",
          title: this.$t("m.AffiliatedUnit"),
        },
      ],
      rightColumns: [
        {
          dataIndex: "stafforstuname",
          title: this.$t("m.Name"),
        },
      ],
      delDataList: [],
      forminitialF: {
        delIds: [],
        waitDelIds: [],
      },
      dataC: [],
      columnsC: [
        {
          dataIndex: "timeName",
          title: this.$t("m.PeriodSchemeName"),
        },
        {
          dataIndex: "timeIndex",
          title: this.$t("m.PeriodSchemeNumber"),
        },
        {
          dataIndex: "startTime",
          title: this.$t("m.Start"),
        },
        {
          dataIndex: "endTime",
          title: this.$t("m.End"),
        },
        {
          dataIndex: "status",
          title: this.$t("m.IsEnabled"),
        },
        {
          dataIndex: "creatorId",
          title: this.$t("m.creatorID"),
        },
        {
          dataIndex: "createDate",
          title: this.$t("m.CreatedDate"),
        },
      ],
      totalA: 0,
      selectedRowKeysListB: [],
      editparams: {
        timeSchemeId: "",
        ids: "",
      },
      selectList:[]
    };
  },
  created() {
    // this.getStaffOrStudInfo();
    this.getTimeScheme();
    this.getDevList();

    getPerages({params:{orgType:1}})
    .then(res => {
      // this.departmentList = res.data
      // this.value = res.data[0].custorgname
      this.forminitialB.ymorgTreeCode = res.data[0].ymorgtreecode
      this.forminitialH.ymOrgTreeCode = res.data[0].ymorgtreecode
      this.getAuthorList();
    })
    .catch(err => {
      console.log(err)
    })
    getWidgetDictionaryList({ params: this.forminitialC })
      .then((res) => {
        this.treeDataList = res.data.data;
        console.log(res);
      })
      .catch((err) => {
        console.log(err);
      });
    getWidgetComboboxList({ params: this.forminitialG })
      .then((res) => {
        this.dataTreeList = res.data.data;
        console.log(res);
      })
      .catch((err) => {
        console.log(err);
      });

    this.parms = Setperms(
      this.$route.fullPath,
      JSON.parse(sessionStorage.getItem("menu"))
    );
    console.log(this.parms);
  },
  methods: {
    pageSizeChange(val, pageNum){
      console.log(val, pageNum)
      this.forminitialH.limit = pageNum
      this.forminitialH.page = val
      this.forminitialH.start = pageNum*(val-1)
      this.getStaffOrStudInfo()

    },
    pageChange(page, val){
      this.forminitialH.page = page
      this.forminitialH.limit = val
      this.forminitialH.start = (page - 1) * val
      this.getStaffOrStudInfo()
      console.log(page,val)

    },
    okB() {
      console.log(this.editparams);
      updateTimeScheme(this.editparams)
        .then((res) => {
          console.log(res);
          if (res.data.success == true) {
            this.getAuthorList();
            this.$message.success(res.data.msg);
          } else {
            this.$message.warning(res.data.msg);
          }
        })
        .catch((err) => {
          this.$message.error("操作失败");
        });
      this.visibleB = false;
    },
    onShowSizeChangeB(page, limit) {
      this.forminitialB.page = page;
      this.forminitialB.limit = limit;
      this.getTimeScheme();
    },
    PagesB(page, pageSize) {
      this.forminitialB.limit = pageSize;
      this.forminitialB.page = page;
      this.forminitialB.start = (page - 1) * pageSize;
      this.getTimeScheme();
    },
    onSelectChangeK(e) {
      this.selectedRowKeysListK = e;
      this.editparams.ids = e.join(",");
      console.log(this.selectedRowKeysListK);
    },
    getTimeScheme() {
      getTimeSchemeList({ params: this.forminitialK })
        .then((res) => {
          this.totalB = res.data.total;
          this.dataB = res.data.data;
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleCancelB() {
      this.visibleB = false;
    },
    isTrue(str) {
      return this.parms.indexOf(str) !== -1;
    },
    edit(text, tags, i) {
      this.editparams.timeSchemeId = tags.id;
      this.visibleB = true;
    },
    onSelectChangeB(e) {
      this.selectedRowKeysListB = e;
    },
    stepOk() {
      if (this.selectedRowKeysListB.length <= 0)
        return this.$message.warning("请选择时段");
      this.forminitialI.ids = this.targetKeys.join(",");

      // this.dataC.forEach(item => {
      //   if(item.id == this.selectedRowKeysListB[0]) {
      //     this.forminitialI.timeSchemeId = item.timeIndex
      //   }
      // })
      this.forminitialI.timeSchemeId = this.selectedRowKeysListB[0];
      saveAuthorize(this.forminitialI)
        .then((res) => {
          if (res.data.success == true) {
            this.getAuthorList();
            this.$message.success(res.data.msg);
          } else {
            this.$message.error(res.data.msg);
          }
          console.log(res);
        })
        .catch((err) => {
          this.$message.error("操作失败");
        });
      this.visibleA = false;
      this.current = 0
      this.targetKeys = []
      this.selectedRowKeysListB = []
      // (this.targetKeys = []), (this.selectedRowKeysListB = []);
    },
    // getTimeScheme(){
    //   getTimeSchemeList({params:this.forminitialJ})
    //   .then(res => {
    //     this.dataC = res.data.data
    //     this.totalA = res.data.total
    //     console.log(res)
    //   })
    //   .catch(err => {
    //     console.log(err)
    //   })
    // },
    onShowSizeChangeA(page, limit) {
      this.forminitialJ.page = page;
      this.forminitialJ.limit = limit;
      this.getTimeScheme();
    },
    PagesA(page, pageSize) {
      this.forminitialJ.limit = pageSize;
      this.forminitialJ.page = page;
      this.forminitialJ.start = (page - 1) * pageSize;
      this.getTimeScheme();
    },
    next() {
      // console.log(this.targetKeys)
      // return
      if (this.targetKeys.length <= 0)
        return this.$message.warning("请选择人员信息");
      this.getTimeScheme();
      this.current++;
    },
    prev() {
      this.current--;
    },
    bindel() {
      delAuthorize(this.forminitialF)
        .then((res) => {
          if (res.data.success == true) {
            this.getAuthorList();
            this.$message.success(res.data.msg);
          } else {
            this.$message.error(res.data.msg);
          }
          console.log(res);
        })
        .catch((err) => {
          this.$message.error("操作失败");
        });
      this.forminitialF.delIds = [];
      this.forminitialF.waitDelIds = [];
      this.$refs.delItem.visible = false;
    },
    deleteAll() {
      if (this.selectedRowKeys.length <= 0)
        return this.$message.warning("请选择人员信息");
        // console.log(this.selectedRowKeys)
        // console.log(this.selectList)
        let delwaitList = []
        this.selectList.forEach(item => {
          if(item.downstatus == 3) {
            delwaitList.push(item.id)
          }
        })

      this.forminitialF.delIds = this.selectedRowKeys.join(",");
      this.forminitialF.waitDelIds = delwaitList.join(",");
      this.$refs.delItem.visible = true;
      console.log(this.forminitialF)
      // console.log(this.selectedRowKeys)
    },

    delitemB(text, tags, i) {
      this.$refs.delItem.visible = true;
      console.log(tags);
    },
    okA() {
      if (this.targetKeys.length <= 0)
        return this.$message.warning("请选择人员信息");
      // saveAuthorize()
      this.forminitialI.ids = this.targetKeys.join(',')
        console.log(this.forminitialI)

      // console.log(this.targetKeys.join(","));
      saveAuthorize(this.forminitialI)
        .then((res) => {
          if (res.data.success == true) {
            this.getAuthorList();
            this.$message.success(res.data.msg);
          } else {
            this.$message.error(res.data.msg);
          }
          console.log(res);
        })
        .catch((err) => {
          this.$message.error("操作失败");
        });
        this.targetKeys = []
      this.visibleA = false;
    },
    triggerShowSearch(showSearch) {
      this.showSearch = showSearch;
      console.log(showSearch);
    },
    onChangeB(targetKeys) {
      this.targetKeys = targetKeys;
    },
    getRowSelection({ selectedKeys, itemSelectAll, itemSelect }) {
      return {
        onSelectAll(selected, selectedRows) {
          const treeSelectedKeys = selectedRows
            .filter((item) => !item.disabled)
            .map(({ key }) => key);
          const diffKeys = selected
            ? difference(treeSelectedKeys, selectedKeys)
            : difference(selectedKeys, treeSelectedKeys);
          itemSelectAll(diffKeys, selected);
        },
        onSelect({ key }, selected) {
          // console.log(key)
          itemSelect(key, selected);
        },
        selectedRowKeys: selectedKeys,
      };
    },

    getStaffOrStudInfo() {
      getStaffOrStudInfoList({ params: this.forminitialH })
        .then((res) => {
          console.log(res);
          this.ipagination.total = res.data.total
          this.mockData = res.data.data.map((item) => {
            return {
              key: item.id + "",
              infotype: item.infotype,
              orgname: item.orgname,
              property: item.property,
              sex: item.sex,
              stafforstucode: item.stafforstucode,
              stafforstuname: item.stafforstuname,
              status: item.status,
              ymorgid: item.ymorgid,
              ymorgtreecode: item.ymorgtreecode,
            };

          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    treeChangeB(e) {
      this.forminitialB.timeSchemeId = e;
      this.getAuthorList();
    },
    onChangeA(e) {
      this.forminitialH.vChild = e.target.checked
      this.getStaffOrStudInfo();
    },
    onSearchA() {
      this.getStaffOrStudInfo();
    },
    treeChangeA(e) {
      this.forminitialH.property = e;
      this.getStaffOrStudInfo();
      console.log(e);
    },
    argumentSelectA(e) {
      console.log(e);
      this.forminitialH.ymOrgTreeCode = e.ymorgtreecode;
      this.getStaffOrStudInfo();
    },
    handleCancelA() {
      this.current = 0;
      this.targetKeys = [];
      this.visibleA = false;
    },
    getStafflist() {
      getStaff({ params: this.forminitialE })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    addshouquan() {
      if (this.selectedRowKeysList.length <= 0)
        return this.$message.warning("请选择设备");
      // this.forminitialI.devIds = this.selectedRowKeysList[0];
      console.log(this.selectedRowKeysList[0]);

      this.getStaffOrStudInfo();
      this.visibleA = true;
      getWidgetDictionaryList({ params: this.forminitialD })
        .then((res) => {
          this.treeListD = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
      getPerages({ params: { orgType: 1 } })
        .then((res) => {
          this.forminitialH.ymOrgTreeCode = res.data[0].ymorgtreecode;
          this.getStaffOrStudInfo();
        })
        .catch((err) => {
          console.log(err);
        });
      this.getStafflist();
    },
    bindownload() {
      if (this.selectedRowKeys.length <= 0) {
        console.log(this.dataA);
        let listdemo = "";
        this.dataA.forEach((item) => {
          listdemo += item.id;
          listdemo += ",";
        });
        this.downIdList = listdemo.substring(0, listdemo.lastIndexOf(","));
        console.log(this.downIdList);
      } else {
        this.downIdList = JSON.parse(JSON.stringify(this.selectedRowKeys)) + "";
      }
      redown({ ids: this.downIdList })
        .then((res) => {
          if (res.data.success == true) {
            this.$message.success(res.data.msg);
          } else {
            this.$message.warning(res.data.msg);
          }

          console.log(res);
        })
        .catch((err) => {
          this.$message.error("操作失败");
          console.log(err);
        });
      this.$refs.bindownload.visible = false;
    },
    reDownload() {
      this.$refs.bindownload.visible = true;
      console.log(this.selectedRowKeys.length <= 0);
      if (this.selectedRowKeys.length <= 0) {
        this.huadalete.text =
          "确定要执行重下？未选择任何记录，如果继续执行，则变更全部记录的状态";
      } else {
        this.huadalete.text =
          "确定要执行重下？如果继续执行，则变更所选记录的状态";
      }
    },
    onSelectChangeA(selectedRowKeys,selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectList = selectedRows
      console.log(selectedRows);
    },
    treeChange(e) {
      this.forminitialB.downStatus = e;
      this.getAuthorList();
      console.log(e);
    },
    onChange(e) {
      this.forminitialB.viewChild = e.target.checked;
      this.getAuthorList();
      // console.log(e)
    },
    onSearch() {
      this.getAuthorList();
    },
    handleCancel() {
      this.visible = false;
    },
    show(text, tags, i) {
      this.visible = true;
      this.imgSrc = tags.imgpath;
      console.log(tags);
    },
    onShowSizeChange(page, limit) {
      this.forminitialB.page = page;
      this.forminitialB.limit = limit;
      this.getAuthorList();
    },
    Pages(page, pageSize) {
      this.forminitialB.limit = pageSize;
      this.forminitialB.page = page;
      this.forminitialB.start = (page - 1) * pageSize;
      this.getAuthorList();
    },
    onShowSizeChangeC(page, limit) {
      this.forminitial.page = page;
      this.forminitial.limit = limit;
      this.getDevList();
    },
    PagesC(page, pageSize) {
      this.forminitial.limit = pageSize;
      this.forminitial.page = page;
      this.forminitial.start = (page - 1) * pageSize;
      this.getDevList();
    },
    argumentSelect(data) {
      this.forminitialB.devIds = "";
      this.forminitialB.ymorgTreeCode = data.ymorgtreecode;
      this.getAuthorList();
      console.log(data);
    },

    onSelectChange(selectedRowKeys, selectedRows) {
      // this.forminitialB.devIds = selectedRows[0].id;
      console.log(selectedRowKeys)
      if(selectedRows[0]) {
        this.forminitialB.devIds = selectedRows[0].id;
      }
      this.forminitialI.devIds = selectedRowKeys.join(',')
      this.selectedRowKeysList = selectedRowKeys;
      this.getAuthorList();
      console.log( this.forminitialI.devIds)
    },
    selectChangetree(e) {
      console.log(e)
      this.forminitialB.infoType = e
      this.getAuthorList()
    },
    // 获取人员信息列表
    getAuthorList() {
      getAuthorizeList({ params: this.forminitialB })
        .then((res) => {
          console.log(res);
          res.data.data.forEach((item) => {
            if (item.allowcard == 1) {
              item.allowcard = "是";
            }
            if (item.sex == 1) {
              item.sex = "男";
            }
            if (item.sex == 2) {
              item.sex = "女";
            }
          });
          this.total = res.data.total;
          this.dataA = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onSearchB() {
      this.getDevList();
    },

    // 获取设备列表
    getDevList() {
      getDeviceList({ params: this.forminitial })
        .then((res) => {
          this.totalC = res.data.total
          this.data = res.data.data;
          console.log(res)
        })
        .catch((err) => {
          console.log(err);
        });
    },
    callback(val) {
      if (val == 1) {
        this.forminitialB.devIds = "";
        this.forminitialB.ymorgTreeCode = "";
        this.getAuthorList();
      }
      if (val == 2) {
        this.forminitialB.devIds = "";
        this.forminitialB.ymorgTreeCode = "001";
        this.getAuthorList();
      }
    },
  },
};
</script>

<style scoped lang="scss">
.steps-content {
  margin-top: 16px;
  border: 1px dashed #e9e9e9;
  border-radius: 6px;
  background-color: #fafafa;
  min-height: 200px;
  /* text-align: center; */
  padding-top: 20px;
  padding-left: 10px;
  padding-right: 10px;
}

.steps-action {
  margin-top: 24px;
}
/deep/ .rig {
  width:70%;
  // flex:2;
  margin-left:20px;
  margin-top:20px;
}
/deep/ .ant-table-placeholder {
  height: 400px;
}
/deep/ .ant-card-body {
  display:flex;
  width: 100%;
}
</style>
